import Articles from './components/Articles';
import HistoricalArticles from './components/HistoricalArticles';
import { fetchArticles, login } from './api/api';
import ClientComponent from './components/ClientComponent'; // 引入 ClientComponent

export default async function Page() {
    let articles = [];
    let error = null;

    try {
        const token = await login();
        articles = await fetchArticles(token);
    } catch (err) {
        console.error('Error fetching articles:', err);
        error = '无法加载文章数据，请稍后重试。';
    }

    return (
        <div>
            <ClientComponent articles={articles} error={error} />
        </div>
    );
}
